home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / math / gle-3.000 / gle-3 / gle / unix_extra.c < prev    next >
C/C++ Source or Header  |  1995-02-27  |  2KB  |  101 lines

  1. #include "int32.h"
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #define true (!false)
  6. #define false 0
  7. int32 coreleft(void)
  8. {
  9.     return 4000000l;
  10. }
  11. char *strlwr(char *s)
  12. {
  13.     char *ss=s;
  14.     while (*s!=0) {*s = tolower(*s); s++;}
  15.     return ss;
  16. }
  17. char *strupr(char *s)
  18. {
  19.     char *ss=s;
  20.     while (*s!=0) {*s = toupper(*s); s++;}
  21.     return ss;
  22. }
  23.  
  24. trim_file(char *s)
  25. {
  26.     char *t;
  27.     t = strchr(s,']');
  28.     if (t!=NULL) memcpy(s,t+1,strlen(t));
  29.     t = strchr(s,';');
  30.     if (s!=NULL) *t = 0;
  31. }
  32. char *getsymbol(char *sym)
  33. {
  34.     static char mystr[200],*s;
  35.     s = getenv(sym);
  36.     if (s==NULL) s = "";
  37.     strcpy(mystr,s);
  38.     return mystr;
  39. }
  40.  
  41.  
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44. #include <sys/types.h>
  45. #include <sys/wait.h>
  46. #define false 0
  47. #define true (!false)
  48.  
  49. FILE *wilddir;
  50. struct ffblk {char *ff_name;};
  51. findfirst(char *wild, struct ffblk *ffblk, int zz)
  52. {
  53.     static char buff[200];
  54.     int op=0;
  55.        #ifdef aix /* AIX with xlc != POSIX */
  56.     union wait *status;
  57.     int p;
  58.        #else
  59.     int status;
  60.     pid_t p;    
  61.        #endif
  62.  
  63.  
  64.        unlink("gledir.tmp");
  65.     p = fork();
  66.     if (p==-1) {perror("Unable to fork ls command \n"); return true;}
  67.     if (p==0) {
  68.         strcpy(buff,"ls ");
  69.         strcat(buff,wild);
  70.         strcat(buff,">gledir.tmp");
  71.         execlp("sh","sh","-c", buff,0);
  72.         exit(1);
  73.     }
  74.        #ifdef aix
  75.     waitpid(p,status,op);
  76.        #else
  77.     waitpid(p,&status,op);
  78.        #endif
  79.     wilddir = fopen("gledir.tmp","r");
  80.     if (wilddir==NULL) {printf("Fork ls failed \n"); return true;}
  81.     if (feof(wilddir)) { fclose(wilddir); return true;}
  82.     fgets(buff,100,wilddir);
  83.     trimcr(buff);
  84.     ffblk->ff_name = buff;
  85.     return false;
  86. }
  87. trimcr(char *s)
  88. {
  89.     s = strchr(s,'\n');
  90.     if (s!=NULL) *s = 0;
  91. }
  92. findnext(struct ffblk *ffblk)
  93. {
  94.     static char buff[200];
  95.     if (feof(wilddir)) { fclose(wilddir); return true;}
  96.     fgets(buff,100,wilddir);
  97.     trimcr(buff);
  98.     ffblk->ff_name = buff;
  99.     return false;
  100. }
  101.